package yongxin.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestServlet  extends HttpServlet{
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
		try {
			this.getDBConnect();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	} 
	
	
	private void getDBConnect() throws Exception {
		 // TODO Auto-generatted method stub
        String url = "jdbc:sqlserver://192.168.1.104:1433;DatabaseName=huamei";
        String user = "sa";
        String pwd = "123";
        Connection conn = null;
        CallableStatement proc = null;//鎵цsql瀛樺偍杩囩▼鐨勬帴鍙?
        ResultSet rs = null;
 
//        璋冪敤瀛樺偍杩囩▼p_1:浠嶤ell琛ㄤ腑鍙栧嚭鏁版嵁
        try{
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            conn = DriverManager.getConnection(url,user,pwd);
            proc = conn.prepareCall("{call p_calcrate()}");
          //  proc.registerOutParameter(1, Types.REAL);
            rs = proc.executeQuery();
            while(rs.next()){
                System.out.println(rs.getString("FAmount"));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            if(rs!=null) rs.close();
            if(proc!=null)proc.close();
            if(conn!=null)conn.close();
        }
	}
}	
